#ifndef __DELEGATE_H__
#define __DELEGATE_H__

struct widget;

#define CONNECT(SENDER,SIGNAL,RECEIVER,SLOT)\
    delegate_connect(SENDER,SIGNAL,RECEIVER,SLOT)

#define SIGNAL(SENDER,SIGNAL,PARAM)\
    delegate_signal(SENDER,SIGNAL,PARAM)

typedef enum
{
    NO_SIGNAL,
    RELEASED,
    PRESSED,
    CLICKED
} signal_t;

typedef struct delegate_receiver
{
    struct widget *receiver; // receiver widget
    void (*slot)(struct widget*,void*); // pointer to the function slot
    struct delegate_receiver *next;
} delegate_receiver_t;

typedef struct delegate_signal
{
    struct widget *sender;
    signal_t signal;
    struct delegate_receiver *receiver_list;
    struct delegate_signal *next;
} delegate_signal_t;

/*! Allocate memory for the delegate hash table, and create dummy notes
 * \param size: size of the hash table
 */
void delegate_alloc(size_t);

/*! Connect a widget:signal with a widget:slot
 *
 * \param sender: widget sending the message
 * \param signal: signal to send
 * \param reveiver: signal receiving the signal
 * \param slot: slot to be called to the signal
 */
EXPORT void delegate_connect(struct widget*,signal_t,struct widget*,
                             void (*)(struct widget*,void*));

/*! Signal all slot connected to widget:signal
 *
 * \param sender: widget sending the message
 * \param signal: signal to send
 * \param param: parameter to send the receiver
 */
EXPORT void delegate_signal(struct widget*,signal_t,void*);

/* Clean up the hash table
 */
void delegate_free();

#endif /* __DELEGATE_H__ */

